﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using IntillisenseLib;

namespace LittleSolution
{
    public partial class ucDefineObjectTemp : UserControl
    {
        public ucDefineObjectTemp()
        {
            InitializeComponent();
        }

        private void btnAddProperties_Click(object sender, EventArgs e)
        {
            frmAddProperties frmAdd = new frmAddProperties();
            //frmAdd.SetParameterValue(tbxName.Text, tbxValue.Text);
            if (frmAdd.ShowDialog()==DialogResult.OK)
            {

            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {            
                btnAddProperties.Enabled = IsValidData()&&comboBox1.SelectedIndex > 0; 
            if (comboBox1.SelectedIndex==1)
            {
                //contact
                tbxName.Text = "FullName";
                tbxName.ReadOnly = true;
            }
            else
            {
                tbxName.ReadOnly = false;
            }
        }
        private bool IsValidData()
        {
            return !String.IsNullOrEmpty(tbxName.Text);            
        }

        private void tbxName_TextChanged(object sender, EventArgs e)
        {
            btnAddProperties.Enabled = IsValidData() && comboBox1.SelectedIndex > 0; 
        }

        private void btnadd_Click(object sender, EventArgs e)
        {
            try
            {
                PlaceholderObject obj = new PlaceholderObject(tbxName.Text, tbxValue.Text);
                AppDoc.GetInstance().AddObj(obj);

                UpdateListView();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);                
            }
            tbxName.SelectAll();
            tbxName.Focus();
        }

        private void UpdateListView()
        {
            dataGridView1.DataSource = AppDoc.GetInstance().ObjRoot.ObjList.ToArray();
        }
    }
}
